﻿using UnityEngine;
using System.Collections;
using System.Xml;
using System.IO;
using System.Text;
using System;
using BaseUtil;
using System.Collections.Generic;

public enum FeatureDataConfigType
{
    Special3DStand,//神器，右手持状态，3D场景特殊的stand动作
    FlyActionFlying,//可以飞，对应的飞行动作
    FlyActionStand, //可以飞，对应的飞行动作
    FlyActionUp,    //可以飞，对应的飞行动作
    FlyActionDown,//可以飞，对应的飞行动作
    StepEffectName,//脚印特效
    StepEffectOffset,//脚印特效偏移值
    EncounterEffectName,//穿体特效
    EncounterEffectBone,
    EncounterEffectTime,
    ResetPhysics,//打断时需要重置物理
}

public class XmlFeatureLinkData : IXMLData
{
    public string id = "";
    public bool save = false;
    public string pos = "";
    public string rotation = "";
    public int loop = 0;

    public override void ReadFromBuf(NetInStream ins)
    {
        ins.Read(ref id);
        ins.Read(ref save);
        ins.Read(ref pos);
        ins.Read(ref rotation);
        ins.Read(ref loop);
    }
    public override void WriteToBuf(NetOutStream outs)
    {
        outs.Write(id);
        outs.Write(save);
        outs.Write(pos);
        outs.Write(rotation);
        outs.Write(loop);
    }
}

public class XmlFeatureResetClothAnimData : IXMLData
{
    public string m_SectionType = string.Empty;
    public string m_AnimName = string.Empty;
    public bool m_IsLast = true;
    public string m_AnimNameOnFly = string.Empty;
    public bool m_IsLastOnFly = true;
    public int m_NextFeatureID = 0;
    public override void WriteToBuf(NetOutStream outs)
    {
        outs.Write(m_SectionType);
        outs.Write(m_AnimName);
        outs.Write(m_IsLast);
        outs.Write(m_AnimNameOnFly);
        outs.Write(m_IsLastOnFly);
        outs.Write(m_NextFeatureID);
    }

    public override void ReadFromBuf(NetInStream ins)
    {
        ins.Read(ref m_SectionType);
        ins.Read(ref m_AnimName);
        ins.Read(ref m_IsLast);
        ins.Read(ref m_AnimNameOnFly);
        ins.Read(ref m_IsLastOnFly);
        ins.Read(ref m_NextFeatureID);
    }
}

public class XmlFeatureBehaviorData : IXMLData
{
    public int start_time = 0;
    public int end_time = 0;
    public string type = "";
    public string param = "";
    public string param2 = "";
    public string param3 = "";
    public string param4 = "";
    public string param5 = string.Empty;
    public string param6 = string.Empty;

    public List<XmlFeatureLinkData> link_effect_list = new List<XmlFeatureLinkData>();
    public List<XmlFeatureResetClothAnimData> reset_cloth_anim_list = new List<XmlFeatureResetClothAnimData>();
    public override void ReadFromBuf(NetInStream ins)
    {
        ins.Read(ref start_time);
        ins.Read(ref end_time);
        ins.Read(ref type);
        ins.Read(ref param);
        ins.Read(ref param2);
        ins.Read(ref param3);
        ins.Read(ref param4);
        ins.Read(ref param5);
        ins.Read(ref param6);
        int count = 0;
        ins.Read(ref count);
        link_effect_list.Capacity = count;
        for (int i = 0; i < count; i++)
        {
            XmlFeatureLinkData data = new XmlFeatureLinkData();
            data.ReadFromBuf(ins);
            link_effect_list.Add(data);
        }
        ins.Read(ref count);
        reset_cloth_anim_list.Capacity = count;
        for (int i = 0; i < count; i++)
        {
            XmlFeatureResetClothAnimData data = new XmlFeatureResetClothAnimData();
            data.ReadFromBuf(ins);
            reset_cloth_anim_list.Add(data);
        }
    }
    public override void WriteToBuf(NetOutStream outs)
    {
        outs.Write(start_time);
        outs.Write(end_time);
        outs.Write(type);
        outs.Write(param);
        outs.Write(param2);
        outs.Write(param3);
        outs.Write(param4);
        outs.Write(param5);
        outs.Write(param6);
        int count = link_effect_list.Count;
        outs.Write(count);
        for (int i = 0; i < count; i++)
        {
            link_effect_list[i].WriteToBuf(outs);
        }
        count = reset_cloth_anim_list.Count;
        outs.Write(count);
        for (int i = 0; i < count; i++)
        {
            reset_cloth_anim_list[i].WriteToBuf(outs);
        }
    }
}

public class XmlFeatureDataConfigSection : IXMLData
{
    public Dictionary<int, string> m_data = new Dictionary<int, string>();
    public override void ReadFromBuf(NetInStream ins)
    {
        XMLBuffHelper.ReadFromBuf(ref m_data, ins);
    }
    public override void WriteToBuf(NetOutStream outs)
    {
        XMLBuffHelper.WriteToBuf(m_data, outs);
    }
}

public class XmlFeatureSectionData : IXMLData
{
    public string type = "";
    public string next_section = "";
    public int next_featureID;
    public int show_time = 0;
    public string param = "";
    public List<XmlFeatureBehaviorData> behavior_list = new List<XmlFeatureBehaviorData>();
    public override void ReadFromBuf(NetInStream ins)
    {
        ins.Read(ref type);
        ins.Read(ref next_section);
        ins.Read(ref next_featureID);
        ins.Read(ref show_time);
        ins.Read(ref param);
        int count = 0;
        ins.Read(ref count);
        behavior_list.Capacity = count;
        for (int i = 0; i < count; i++)
        {
            XmlFeatureBehaviorData data = new XmlFeatureBehaviorData();
            data.ReadFromBuf(ins);
            behavior_list.Add(data);
        }
    }
    public override void WriteToBuf(NetOutStream outs)
    {
        outs.Write(type);
        outs.Write(next_section);
        outs.Write(next_featureID);
        outs.Write(show_time);
        outs.Write(param);
        int count = behavior_list.Count;
        outs.Write(count);
        for (int i = 0; i < count; i++)
        {
            behavior_list[i].WriteToBuf(outs);
        }
    }
}
public class XmlFeatureUseCaseData : IXMLData
{
    public string start_section = "";
    public string pos_offset = "";
    public string rotation = "";
    public int ui_camera_id = 0;
    public bool need_hide_first_frame = false;
    private List<int> m_hide_pet_level_list = null;// new H3DList<int>();
    public List<int> hide_pet_level_list
    {
        get
        {
            if (null == m_hide_pet_level_list)
            {
                m_hide_pet_level_list = new List<int>();
            }
            return m_hide_pet_level_list;
        }
    }
    public XmlFeatureSectionData global_section = new XmlFeatureSectionData();
    public XmlFeatureDataConfigSection data_config_section = new XmlFeatureDataConfigSection();
    private List<XmlFeatureSectionData> m_section_list = null;// new H3DList<XmlFeatureSectionData>();
    public List<XmlFeatureSectionData> section_list
    {
        get
        {
            if (null == m_section_list)
            {
                m_section_list = new List<XmlFeatureSectionData>();
            }

            return m_section_list;
        }
    }
    public override void ReadFromBuf(NetInStream ins)
    {
        ins.Read(ref start_section);
        ins.Read(ref pos_offset);
        ins.Read(ref rotation);
        ins.Read(ref ui_camera_id);
        ins.Read(ref need_hide_first_frame);
        global_section.ReadFromBuf(ins);
        data_config_section.ReadFromBuf(ins);
        int count = 0;
        ins.Read(ref count);
        m_section_list = new List<XmlFeatureSectionData>(count);
        for (int i = 0; i < count; i++)
        {
            XmlFeatureSectionData data = new XmlFeatureSectionData();
            data.ReadFromBuf(ins);
            m_section_list.Add(data);
        }
        ins.Read(ref count);
        //hide_pet_level_list.Clear();
        //hide_pet_level_list.Capacity = count;
        m_hide_pet_level_list = new List<int>(count);
        for (int i = 0; i < count; i++)
        {
            int level = 0;
            ins.Read(ref level);
            m_hide_pet_level_list.Add(level);
        }

    }
    public override void WriteToBuf(NetOutStream outs)
    {
        outs.Write(start_section);
        outs.Write(pos_offset);
        outs.Write(rotation);
        outs.Write(ui_camera_id);
        outs.Write(need_hide_first_frame);
        global_section.WriteToBuf(outs);
        data_config_section.WriteToBuf(outs);
        int count = section_list.Count;
        outs.Write(count);
        for (int i = 0; i < count; i++)
        {
            section_list[i].WriteToBuf(outs);
        }
        outs.Write(hide_pet_level_list.Count);
        for (int i = 0; i < hide_pet_level_list.Count; i++)
        {
            outs.Write(hide_pet_level_list[i]);
        }

    }
}
public class XmlNewFeatureData : IXMLData
{
    public int id = 0;
    public int level = 0;
    public bool fly_show = false;
    public bool enable = true;
    public bool special_show = false;    //特殊表现使用，不走通用播放流程，例如，神器的切换表现
    public XmlFeatureUseCaseData ui_data = new XmlFeatureUseCaseData();
    public XmlFeatureUseCaseData ingame_data = new XmlFeatureUseCaseData();
    public bool on_ground_hide = false;
    public int callback_event_type = -1;
    public override void ReadFromBuf(NetInStream ins)
    {
        ins.Read(ref id);
        ins.Read(ref level);
        ins.Read(ref fly_show);
        ins.Read(ref enable);
        ui_data.ReadFromBuf(ins);
        ingame_data.ReadFromBuf(ins);
        
        ins.Read(ref special_show);
		ins.Read(ref on_ground_hide);
		ins.Read(ref callback_event_type);
    }
    public override void WriteToBuf(NetOutStream outs)
    {
        outs.Write(id);
        outs.Write(level);
        outs.Write(fly_show);
        outs.Write(enable);
        ui_data.WriteToBuf(outs);
        ingame_data.WriteToBuf(outs);
        
        outs.Write(special_show);
		outs.Write(on_ground_hide);
		outs.Write(callback_event_type);
    }

    public override string ToString()
    {
        return "featureID:" + id + ", enable:" + enable;
    }
}
public class NewFeatureList : IXMLData
{
    public ArrayList item_list = new ArrayList();
    public override void WriteToBuf(NetOutStream outs)
    {
        int count = item_list.Count;
        outs.Write(count);
        for (int i = 0; i < count; i++)
        {
            (item_list[i] as XmlNewFeatureData).WriteToBuf(outs);
        }
    }
    public override void ReadFromBuf(NetInStream ins)
    {
        int count = 0;
        ins.Read(ref count);
        item_list.Capacity = count;
        for (int i = 0; i < count; i++)
        {
            XmlNewFeatureData item = new XmlNewFeatureData();
            item.ReadFromBuf(ins);
            item_list.Add(item);
        }
    }
}
